package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymttest.business.service.shenqi.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.cdfgeteway.resp.PointsVo;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CancelOrderTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.req.CancelOrderReq;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.CancelOrderCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.database.model.AccountEntry;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.OrderStatusLogPo;
import com.ymttest.database.sharding.db.sharding.model.UserRefundFundDetailPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 取消订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SqCancelOrder {

	private static CancelOrderReq cancelorderReq;
	private static CancelOrderCall cancelordercall;

	private static OrderShardingWapper database = new OrderShardingWapper();

	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));
	private static long cdfMembergoodsOwnerId = ShenqiUserSet.cdfMembergoodsOwnerId;
	private static long multiCDFCodeGoodsOwnerId = ShenqiUserSet.multiCDFCodeGoodsOwnerId;
	private static long macaoCDFGoodsOwnerId = ShenqiUserSet.macaoCDFGoodsOwnerId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消订单");
	}

	@Before
	public void caseUp() {
		cancelorderReq = new CancelOrderReq();
		cancelordercall = new CancelOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelordercall.getOpurl());
		database.activeDeadCommunicationsLink(database);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 校验订单表状态，单主状态操作日志表
	 * @throws InterruptedException 
	 */
	public static void verifyOrderStatus(int orderStatus, long orderId,
			long userId, CancelOrderTypeEnum type, String cancelReason) throws InterruptedException {

		// 订单表(order)
		OrderPo ymtOrders = database.selectOrderbyOrderId(orderId);

		Logger.comment(String.format("验证订单表(order)表 orderId: %s", orderId));

		Logger.verifyEquals(orderStatus, ymtOrders.getOrderStatus(),
				"验证orderStatus");

		// 订单主状态操作日志表(order_status_log)
		OrderStatusLogPo orderStatusLogPo = database
				.selectOrderStatusLogByOrderId(orderId);

		Logger.comment("验证订单主状态操作日志表(order_status_log)");

		String cancelMemo = "";

		int orderStatusMemo = 400000;

		switch (type.getCode()) {
		case 1:
			cancelMemo = "买家取消订单";
			orderStatusMemo = 100000;
			break;
		case 2:
			cancelMemo = cancelReason;
			orderStatusMemo = 200000;
			break;
		case 3:
			cancelMemo = cancelReason;
			orderStatusMemo = 300000;
			break;
		case 4:
			cancelMemo = "系统取消订单";
			orderStatusMemo = 400000;
			break;
		case 5:
			cancelMemo = "风控系统自动取消订单";
			orderStatusMemo = 500000;
			break;
		case 7:
			cancelMemo = "收件人额度超过2万金额取消订单";
			orderStatusMemo = 700000;
			break;
		case 8:
			cancelMemo = "全款未支付取消订单";
			orderStatusMemo = 800000;
			break;
		case 9:
			cancelMemo = "买手未发货取消订单";
			orderStatusMemo = 900000;
			break;
		case 10:
			cancelMemo = "系统取消订单";
			orderStatusMemo = 400000;
			break;
		default:
			cancelMemo = cancelReason;
			break;
		}
		
		Logger.verifyEquals(orderStatusMemo, ymtOrders.getOrderStatusMemo(),
				"检验OrderStatusMemo");

		Logger.comment("验证order_status_log表");
		Logger.verifyEquals(cancelMemo, orderStatusLogPo.getMemo(), "检验Memo");

		// 支付定金订单
		Boolean payEarnestOrder = ymtOrders.getEarnestPaymentId() != null
				&& ymtOrders.getPaymentId() == null;
		
		// 下单使用积分
		Boolean useIntegral = Utils.zeroIfNull(ymtOrders.getIntegral()) > 0;
		
		Boolean isCDFIntegral = Utils.zeroIfNull(ymtOrders.getIntegralServiceType()) == 2;

		// 支付过定金或使用积分订单
		if (null != ymtOrders.getPaymentId() || payEarnestOrder
				|| useIntegral) {

			UserRefundFundDetailPo expectedUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectedUserRefundFundDetailPo.setOrderId(orderId);
			expectedUserRefundFundDetailPo.setBizNo(String.valueOf(orderId));
			expectedUserRefundFundDetailPo.setAccountAmount(BigDecimal.ZERO);
			expectedUserRefundFundDetailPo
					.setThirdpartyDiscount(BigDecimal.ZERO);
			expectedUserRefundFundDetailPo.setAccountRefundStatus(-1);
			expectedUserRefundFundDetailPo.setRetryTimes(0);
			expectedUserRefundFundDetailPo.setRebateAmount(BigDecimal.ZERO);
			expectedUserRefundFundDetailPo.setIsShenqi(true);

			UserRefundFundDetailPo userRefundFundDetailPo = null;
			
			if (payEarnestOrder) {

				expectedUserRefundFundDetailPo.setPaymentId(ymtOrders
						.getEarnestPaymentId());
				expectedUserRefundFundDetailPo.setThirdpartyAmount(ymtOrders
						.getEarnestAmount());
				expectedUserRefundFundDetailPo.setBizType(5);

				userRefundFundDetailPo = database
						.selectUserRefundFundDetailByBizno(String
								.valueOf(orderId));
				
				// 定金订单，买家超时未付全款，定金罚没，没有退款
				if (YMTDateUtil.diffSecond(ymtOrders.getPaymentEndTime(),
						YMTDateUtil.getDate()) > 0) {
					
					if (null != userRefundFundDetailPo)
						Logger.verifyEquals(false, userRefundFundDetailPo.getBizType() == 5,
								"定金订单，买家超时未付全款，定金罚没，没有资金退款");
					else
						Logger.verifyEquals(null, userRefundFundDetailPo,
								"定金订单，买家超时未付全款，定金罚没，没有资金退款");
					
					return;
				}		
			} else {
				
				if (isCDFIntegral) {

					Thread.sleep(5000);
				}

				expectedUserRefundFundDetailPo.setPaymentId(0L);
				expectedUserRefundFundDetailPo
						.setThirdpartyAmount(BigDecimal.ZERO);
				expectedUserRefundFundDetailPo.setBizType(2);
				expectedUserRefundFundDetailPo.setThirdpartyRefundStatus(4);
				expectedUserRefundFundDetailPo.setIntegralRefundStatus(4);
				expectedUserRefundFundDetailPo.setRefundIntegral(ymtOrders
						.getIntegral());

				userRefundFundDetailPo = database
						.selectUserRefundFundDetailByBizno(String
								.valueOf(orderId));
			}

			RefundService.verifyUserRefundFundDetailDb(
					expectedUserRefundFundDetailPo, userRefundFundDetailPo);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_001() {
		Logger.start(true, "代购神器订单支付前,买家取消订单成功,订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_002() {
		Logger.start(true, "代购神器订单支付后,买家取消订单失败");

		// 神器订单取消，网关处无法快速退款，需要去第三方校验，故资金表无数据
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("107", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(
					String.format("已支付订单无法取消，请升级APP或联系管理员", orderId),
					cancelordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_003() {
		Logger.start(true, "代购神器订单支付后,使用盛付通， goodsOwnerId取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("107", cancelordercall.getBCode(), "验证bcode");
			Logger.verifyEquals(
					String.format("已支付订单无法取消，请升级APP或联系管理员", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_005() {
		Logger.start(true, "代购神器订单支付前,代理商取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(sellerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("103", cancelordercall.getBCode(), "验证bcode");
			Logger.verifyEquals(
					String.format("用户%s不是订单%s的所有者", sellerId, orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_006() {
		Logger.start(true, "代购神器订单支付前, 货主取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();
			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_007() {
		Logger.start(true, "代购神器接单后,goodsOwnerId取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("107", cancelordercall.getBCode(), "验证bcode");
			Logger.verifyEquals(
					String.format("已支付订单无法取消，请升级APP或联系管理员", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_009() {
		Logger.start(true, "代购神器外币订单下单后,goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							true);
			String currency = productBean.getCurrency();
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO,
							autotest_goodsOwnerId, currency);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_011() {
		Logger.start(true, "线下支付订单，使用了买手优惠券,货头确认收单成功，卖家取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp resp = SqTradingCallService.placeOrder1(
					productBean, productBean.getSellerId(), true);

			OrderPo order = resp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			Long userId = resp.getUserId();

			SqTradingCallService.payOrder(userId, resp.getTradingId(),
					"wxsqBuyer", "200");
			TradingSyncService.getSyncResult(orderId);

			SqTradingCallService.confirmOfflinePay(orderId,
					autotest_goodsOwnerId);
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(productBean.getSellerId());

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_012() {
		Logger.start(true, "线下支付订单，使用了买手优惠券,买家确认线上支付成功，卖家取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp resp = SqTradingCallService.placeOrder1(
					productBean, productBean.getSellerId(), true);

			OrderPo order = resp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			Long userId = resp.getUserId();

			SqTradingCallService.payOrder(userId, resp.getTradingId(),
					"wxsqBuyer", "200");
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(productBean.getSellerId());

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_013() {
		Logger.start(true, "线下支付订单，使用了买手优惠券,买家确认线上支付成功，买家取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp resp = SqTradingCallService.placeOrder1(
					productBean, productBean.getSellerId(), true);

			OrderPo order = resp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			Long userId = resp.getUserId();

			SqTradingCallService.payOrder(userId, resp.getTradingId(),
					"wxsqBuyer", "200");
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map<String, Long> m = new HashMap<>();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			List<AccountEntry> res = new AccountWapper()
					.selectAccountEntryByBizNo(m);

			DataUtil.verifyDecimalEquals(0, res.size(), "校验取消订单退款入账流水金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_014() {
		Logger.start(true, "线下支付订单，使用了买手优惠券,买家确认线上支付成功，系统取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp resp = SqTradingCallService.placeOrder1(
					productBean, productBean.getSellerId(), true);

			OrderPo order = resp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			Long userId = resp.getUserId();

			SqTradingCallService.payOrder(userId, resp.getTradingId(),
					"wxsqBuyer", "200");
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map<String, Long> m = new HashMap<>();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			List<AccountEntry> res = new AccountWapper()
					.selectAccountEntryByBizNo(m);

			DataUtil.verifyDecimalEquals(0, res.size(), "校验取消订单退款入账流水金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_015() {
		Logger.start(true, "线下支付订单，使用了买手优惠券,买家确认线上支付成功，客服取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp resp = SqTradingCallService.placeOrder1(
					productBean, productBean.getSellerId(), true);

			OrderPo order = resp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			Long userId = resp.getUserId();

			SqTradingCallService.payOrder(userId, resp.getTradingId(),
					"wxsqBuyer", "200");
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map<String, Long> m = new HashMap<>();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			List<AccountEntry> res = new AccountWapper()
					.selectAccountEntryByBizNo(m);

			DataUtil.verifyDecimalEquals(0, res.size(), "校验取消订单退款入账流水金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_016() {
		Logger.start(true, "线下支付订单，使用了买手优惠券, 系统自动取消订单,订单状态为18 系统自动取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, productBean.getSellerId(), true);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			// 修改下单时间
			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -1);

			record.setAddTime(calendar.getTime());

			database.orderMapper.updateByPrimaryKeySelective(record);

			Thread.sleep(3000);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"4\",\"orderId\":"
					+ orderId + ",\"userId\":" + userId + "}";

			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://sqoptrade.iapi.shop2cn.com/api/Buyer/AutoCancelOrder");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database.selectOrderbyOrderId(orderId);

			Logger.verifyEquals(18, actualOrder.getOrderStatus(),
					"验证orderStatus");

			Map<String, Long> m = new HashMap<>();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			List<AccountEntry> res = new AccountWapper()
					.selectAccountEntryByBizNo(m);

			DataUtil.verifyDecimalEquals(0, res.size(), "校验取消订单退款入账流水金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_017() {
		Logger.start(true, "线下支付订单，使用了买手优惠券,买家确认线上支付成功, 系统自动取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, productBean.getSellerId(), true);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();

			SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "200");

			// 修改下单时间
			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -1);

			record.setAddTime(calendar.getTime());

			database.orderMapper.updateByPrimaryKeySelective(record);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"4\",\"orderId\":"
					+ orderId + ",\"userId\":" + userId + "}";

			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://sqoptrade.iapi.shop2cn.com/api/Buyer/AutoCancelOrder");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database.selectOrderbyOrderId(orderId);

			Logger.verifyEquals(1, actualOrder.getOrderStatus(),
					"验证orderStatus");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_018() {
		Logger.start(true, "代购神器直销商，使用了虚拟库存,goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, productBean.getSellerId(), 2);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_019() {
		Logger.start(true, "渠道商一次下单多个虚拟库存商品,生产多个订单,goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeVStockOrder2(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(1).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 支付成功后，不能取消订单
	public void Tc_CancelOrder_020() {
		Logger.start(true, "代购神器外币标价商品，直销订单并支付，支付人民币，代购神器订单支付好后, 货主取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long dualPayModeGoodsOwnerId = 500583265L;

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) dualPayModeGoodsOwnerId, 0, false,
							true);
			String currency = productBean.getCurrency();

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, 1, dualPayModeGoodsOwnerId,
							productBean.getCurrency());
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRateForTe = DGSQBaseService
					.getCurrencyConfig(currency).getExchangeRmbRateForTe();

			// 支付网关支付回调交易
			SQPayGateWayCallService
					.DGSQNotifyCall(
							String.valueOf(thirdTradingId),
							totalPrice.subtract(BigDecimal.ZERO)
									.multiply(exchangeRmbRateForTe)
									.setScale(2, BigDecimal.ROUND_HALF_DOWN)
									.toString(), userId.intValue(),
							BigDecimal.ZERO.toPlainString(), 6010);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Thread.sleep(5000);

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();
			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_021() {
		Logger.start(true, "代购神器多订单组合支付后,使用hipopay，goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithSuppliers(autotest_goodsOwnerId, 1,
							500058147L, 5);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_022() {
		Logger.start(true, "代购神器多订单组合支付后,使用盛付通，goodsOwnerId取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithSuppliers(autotest_goodsOwnerId, 1,
							500058147L, 5);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("抱歉，该订单因合并支付无法取消", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_023() {
		Logger.start(true, "代购神器订单支付后,使用盛付通， 订单支付时间超过90天，goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			OrderPo record = database.selectOrderbyOrderId(order.getOrderId());

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_YEAR, -90);

			record.setPaidTime(calendar.getTime());

			// 修改支付时间
			database.orderMapper.updateByPrimaryKey(record);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_024() {
		Logger.start(true,
				"代购神器订单支付后,使用hipoPay， 订单支付时间超过90天，goodsOwnerId取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			OrderPo record = database.selectOrderbyOrderId(order.getOrderId());

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_YEAR, -91);

			record.setPaidTime(calendar.getTime());

			// 修改支付时间
			database.orderMapper.updateByPrimaryKey(record);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("102", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("抱歉，该订单已超过退款期限，无法取消", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_025() {
		Logger.start(true,
				"代购神器多订单组合支付后,使用hipopay，订单支付时间超过89天,goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithSuppliers(autotest_goodsOwnerId, 1,
							500058147L, 5);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();
			long goodsOwnerId = placeOrderResp.getOrderList().get(0)
					.getOrderPo().getGoodsOwnerId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);

			// 需要等待生成神器结算单才能取消
			Thread.sleep(20000);

			Logger.comment("前置数据准备结束");

			OrderPo record = database.selectOrderbyOrderId(order.getOrderId());

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_YEAR, -90);

			record.setPaidTime(calendar.getTime());

			// 修改支付时间
			database.orderMapper.updateByPrimaryKey(record);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_026() {
		Logger.start(true,
				"代购神器外币标价商品，商品标价与货头结算币种不一致，直销订单并支付，支付人民币，代购神器订单支付好后, 货主取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long multiCurrencyGoodsOwnerId = 500899225L;

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) multiCurrencyGoodsOwnerId, 0,
							false, "JPY");
			String currency = productBean.getCurrency();

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, null, 1,
							multiCurrencyGoodsOwnerId,
							productBean.getCurrency());
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6000");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRate = DGSQBaseService.getCurrencyConfig(
					currency).getExchangeRmbRate();

			// 支付网关支付回调交易
			SQPayGateWayCallService
					.DGSQNotifyCall(
							String.valueOf(thirdTradingId),
							totalPrice.subtract(BigDecimal.ZERO)
									.multiply(exchangeRmbRate)
									.setScale(2, BigDecimal.ROUND_HALF_DOWN)
									.toString(), userId.intValue(),
							BigDecimal.ZERO.toPlainString(), "CNY", "USD");

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Thread.sleep(5000);

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();
			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_027() {
		Logger.start(true,
				"代购神器外币标价商品，商品标价与货头结算币种不一致，直销订单并支付，支付人民币，代购神器订单支付好后, 货主取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long notSupportHpCNYGoodsOwnerId = 500956988L;

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) notSupportHpCNYGoodsOwnerId, 0,
							false);
			String currency = productBean.getCurrency();

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, null, 1,
							notSupportHpCNYGoodsOwnerId, currency);
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6000");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRate = DGSQBaseService.getCurrencyConfig(
					"USD").getExchangeRmbRate();

			totalPrice = totalPrice.multiply(
					BigDecimal.ONE.divide(exchangeRmbRate, 7,
							BigDecimal.ROUND_HALF_DOWN)).setScale(2,
					BigDecimal.ROUND_HALF_DOWN);

			// 支付网关支付回调交易
			SQPayGateWayCallService
					.DGSQNotifyCall(
							String.valueOf(thirdTradingId),
							totalPrice.subtract(BigDecimal.ZERO)
									.setScale(2, BigDecimal.ROUND_HALF_DOWN)
									.toString(), userId.intValue(),
							BigDecimal.ZERO.toPlainString(), currency, currency);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Thread.sleep(5000);

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();
			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_029() {
		Logger.start(true, "代购神器订单支付后,退货退款成功，goodsOwnerId取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.orderRefundSuccess(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("102", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("此单有退货/退款，无法取消", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_030() {
		Logger.start(true, "代购神器订单支付后,退货退款失败，goodsOwnerId取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.orderRefundFailed(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_031() {
		Logger.start(true, "代购神器订单已发货,取消订单，走整单退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long goodsOwnerId = order.getGoodsOwnerId();
			BigDecimal amount = placeOrderResp.getPayableAmount();
			Long userId = placeOrderResp.getUserId();

			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(3000);

			SqTradingCallService.sellerAcceptOrder(orderId);
			TradingSyncService.getSyncResult(orderId);

			SqTradingCallService.delivery(goodsOwnerId, orderId, null, null);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(3, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_032() {
		Logger.start(true, "代购神器微信直连,取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain(
							ShenqiUserSet.chainStoreGoodsOwnerId.intValue(), 0,
							false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeChainStoreOrder(productBean,
							ShenqiUserSet.chainStoreGoodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "501476063", "6401");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6401);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			// goodsOwner取消的时候，为卖家goodsOwnerId
			cancelorderReq.setUserId(ShenqiUserSet.chainStoreGoodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_033() {
		Logger.start(true, "代购神器订单支付前,使用积分，买家取消订单成功,订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			int mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) mchId, 0, false);

			GodPointsService.saveCreditPolicyReq((long) mchId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) mchId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, mchId, 10L);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_034() {
		Logger.start(true, "代购神器订单支付后,使用积分，已支付，货头取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			int mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) mchId, 0, false);

			GodPointsService.saveCreditPolicyReq((long) mchId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) mchId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, mchId, 10L);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					(int) userId, BigDecimal.ZERO.toPlainString());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId((long) mchId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("107", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(
					String.format("已支付订单无法取消，请升级APP或联系管理员", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_035() {
		Logger.start(true, "中免大会员订单支付,使用积分，已支付，货头取消订单成功,订单状态为12 货头取消订单");
		try {

			// 获取下单前中免大会员可用积分和冻结积分
			PointsVo pointsVo = CDFMemberService.getCDFMemberUserPoints(
					cdfMembergoodsOwnerId, 26080783L);

			Long balance = pointsVo.getBalance();
			Long frozenBalance = pointsVo.getFrozenBalance();

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithCDFMember(productBean,
							cdfMembergoodsOwnerId, 10L);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId((long) cdfMembergoodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			PointsVo afterPointsVo = CDFMemberService.getCDFMemberUserPoints(
					cdfMembergoodsOwnerId, 26080783L);

			Logger.verifyEquals(balance, afterPointsVo.getBalance(),
					"验证下单后的balance");
			Logger.verifyEquals(frozenBalance,
					afterPointsVo.getFrozenBalance(), "验证下单后的frozenBalance");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_036() {
		Logger.start(true, "一品多码订单下单， 货头取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) multiCDFCodeGoodsOwnerId,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeMultiCDFCodeOrder(productBean,
							multiCDFCodeGoodsOwnerId);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId((long) multiCDFCodeGoodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_037() {
		Logger.start(true, "定金订单下单， 买家取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeBookingOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();
			long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_038() {
		Logger.start(true, "定金订单下单， 货头取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeBookingOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();
			long orderId = order.getOrderId();

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(autotest_goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_040() {
		Logger.start(true, "已支付定金订单， 买家取消订单，取消失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeBookingOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();
			Long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();

			// 支付定金
			long thirdTradingId = SqTradingBookingOrderCallService
					.payBookingOrder(userId, placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId), placeOrderResp
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), userId.intValue(),
					BigDecimal.ZERO.toPlainString(), productBean.getCurrency());

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("哈尼，已支付定金预售订单不能取消~", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_041() {
		Logger.start(true, "已支付定金订单， 货头取消订单，取消成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeBookingOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();
			Long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();

			// 支付定金
			long thirdTradingId = SqTradingBookingOrderCallService
					.payBookingOrder(userId, placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId), placeOrderResp
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), userId.intValue(),
					BigDecimal.ZERO.toPlainString(), productBean.getCurrency());

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(autotest_goodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_042() {
		Logger.start(true, "已支付定金订单， 超过paymentEndTime，系统自动取消");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			TradingServiceResp placeOrderResp = SqTradingBookingOrderCallService
					.placeBookingOrder(productBean);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();
			Long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();

			// 支付定金
			long thirdTradingId = SqTradingBookingOrderCallService
					.payBookingOrder(userId, placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId), placeOrderResp
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), userId.intValue(),
					BigDecimal.ZERO.toPlainString(), productBean.getCurrency());

			Thread.sleep(5000);

			// 修改paymentEndTime
			database.clearCache();

			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);

			record.setPaymentEndTime(calendar.getTime());

			// 修改二次确认时间
			database.orderMapper.updateByPrimaryKey(record);

			// 自动取消二次确认订单
			SqTradingBookingOrderCallService
					.bookingOrderUserViolationAutoCancel(orderId);

			String cancelReason = "买家超时未付全款，系统自动取消";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BOOKINGORDER_UNPAID_FULLAMOUNT);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(autotest_goodsOwnerId);

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_043() {
		Logger.start(true, "二次确认订单， 超过paymentEndTime，用户手动取消");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			TradingServiceResp resp = SqTradingBookingOrderCallService
					.placeSecondConfirmOrder(productBean);

			long orderId = resp.getOrderList().get(0).getOrderId();

			Thread.sleep(5000);

			// 修改paymentEndTime
			database.clearCache();

			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);

			record.setPaymentEndTime(calendar.getTime());

			// 修改二次确认时间
			database.orderMapper.updateByPrimaryKey(record);

			String cancelReason = "买家取消二次确认超时订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(cdfMembergoodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_044() {
		Logger.start(true, "中免澳门大会员订单,使用积分，货头取消订单成功,订单状态为12 货头取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) macaoCDFGoodsOwnerId, 0, false, true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeCDFMacaoOrderIntegral(productBean, 100L);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			Thread.sleep(5000);

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId((long) macaoCDFGoodsOwnerId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}